/*项目考勤管理
* 详情*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frametrim/activity/projectAttendanceManagmentSearchPage.dart';
import 'package:frametrim/app/app_navigator.dart';
import 'package:frametrim/utility/pickerDialogs.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/utility/timeUtil.dart';
import 'package:frametrim/views/appbar_black.dart';
import 'package:frametrim/views/appbar_search.dart';
import 'package:sticky_headers/sticky_headers.dart';

import 'attendanceManagerRecordPage.dart';

class PriojectAttendanceMDPage extends StatefulWidget
    implements PreferredSizeWidget {
  @override
  State<StatefulWidget> createState() => PriojectAMDState();

  @override
  Size get preferredSize => Size.fromHeight(75);
}

class PriojectAMDState extends State<PriojectAttendanceMDPage> {
  TextEditingController controller = TextEditingController();
   late String mYear;
  late String mMonth;

  @override
  void initState() {
    super.initState();
    mYear=TimeUtil.getYear().toString();
    mMonth=TimeUtil.getMonth().toString();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: AnnotatedRegion(
          value: SystemUiOverlayStyle.dark,
          child: Column(
            children: [
              AppbarSearchTitle(
                imgStr: 'image/imv_back.png',
                controller: controller,
                callback: (str) {
                  AppNavigator.push(context, ProjectAMSearchPage());
                },
                isNeedJump: true,
              ),
              Expanded(
                child: MediaQuery.removePadding(
                  context: context,
                  child: ListView(
                    children: [
                      buildTopView(),//可滚动消失头部
                      StickyHeader(
                        header: buildSuspend(),//滚动悬浮部分
                        content: Column(
                          children: buildList(),//下部列表
                        ),
                      )
                    ],
                  ),
                  removeTop: true,
                ),
              )
            ],
          )),
    );
  }

  /*悬浮部分*/
  Widget buildSuspend() {
    return Container(
      height: 50,
      margin: EdgeInsets.symmetric(horizontal: 10),
      width: Screen.width,
      decoration: BoxDecoration(
          color: SQColor.color_DFE2EF,
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(5),
              topRight: Radius.circular(5),
              bottomLeft: Radius.circular(0),
              bottomRight: Radius.circular(0))),
      child: Row(
        children: [
          Container(
            padding: EdgeInsets.only(left: 10),
            width: 80,
            child: Text(
              '姓名',
              style: TextStyle(fontSize: 15, color: SQColor.color_222222),
            ),
          ),
          Container(
            width: 80,
            child: Text(
              '班组',
              style: TextStyle(fontSize: 15, color: SQColor.color_222222),
            ),
          ),
          Container(
            width: 80,
            child: Text(
              '岗位',
              style: TextStyle(fontSize: 15, color: SQColor.color_222222),
            ),
          ),
          Expanded(
            child: Container(
              padding: EdgeInsets.only(right: 10),
              alignment: Alignment.centerRight,
              child: Text(
                '最新记录',
                style: TextStyle(fontSize: 15, color: SQColor.color_222222),
              ),
            ),
          )
        ],
      ),
    );
  }

  /*顶部-信息*/
  Widget buildTopView() {
    return Container(
      margin: EdgeInsets.only(top: 10,left: 10,right: 10),
      padding: EdgeInsets.symmetric(horizontal: 10, vertical: 15),
      //给Container设置背景图片
      decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage('image/icon_background.png'),
              fit: BoxFit.fill)),
      child: Column(
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                width: 3,
                height: 18,
                decoration: ShapeDecoration(
                    color: SQColor.primary,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(Radius.circular(5)))),
              ),
              SizedBox(
                width: 10,
              ),
              Text(
                '二七华侨城',
                style: TextStyle(fontSize: 20, color: SQColor.color_222222),
              ),
              Expanded(child: Container()),
              GestureDetector(
                  onTap: () {
                    PickerDialogs.showYearMonthPicker(context, '选择时间', (result) {
                      setState(() {
                        mYear = result.year.toString();
                        mMonth = result.month.toString();
                      });
                    });
                  },
                  child: Container(
                    height: 35,
                    padding: EdgeInsets.only(left: 15, right: 15),
                    decoration: BoxDecoration(
                      borderRadius:
                        BorderRadius.all(Radius.circular(17.5)),
                      border: Border.all(color: Colors.black,width: 1)
                       ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Text(
                          '${mYear}年${mMonth}月',
                          style: TextStyle(fontSize: 16, color: SQColor.color_333333),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Image.asset(
                          'image/icon_down.png',
                          width: 13,
                          height: 13,
                        ),
                      ],
                    ),
                  )),
            ],
          ),
          SizedBox(
            height: 30,
          ),
          Row(
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '856',
                    style: TextStyle(fontSize: 20, color: SQColor.color_222222),
                  ),
                  Text(
                    '总在场人数',
                    style: TextStyle(fontSize: 14, color: SQColor.color_666666),
                  ),
                ],
              ),
              Expanded(child: Container()),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '589',
                    style: TextStyle(fontSize: 20, color: SQColor.color_222222),
                  ),
                  Text(
                    '今日考勤人数',
                    style: TextStyle(fontSize: 14, color: SQColor.color_666666),
                  ),
                ],
              ),
              Expanded(child: Container()),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '55%',
                    style: TextStyle(fontSize: 20, color: SQColor.color_222222),
                  ),
                  Text(
                    '今日出勤率',
                    style: TextStyle(fontSize: 14, color: SQColor.color_666666),
                  ),
                ],
              ),
            ],
          ),
          SizedBox(
            height: 15,
          ),
        ],
      ),
    );
  }

/*list*/
  List<Widget> buildList() {
    List<Widget> children = [];
    for (var i = 0; i < 50; i++) {
      children.add(GestureDetector(
        onTap: (){
          AppNavigator.push(context, AttendanceManagerRecordPage());
        },
        child: Container(
          margin:EdgeInsets.symmetric(horizontal: 10) ,
          child: buildItem(),
        ),
      ));
    }
    return children;
  }

/*item*/
  Widget buildItem() {
    return Column(
      children: [
        SizedBox(height: 10,),
        Row(
          children: [
            Container(
              padding: EdgeInsets.only(left: 10),
              width: 80,
              child: Text(
                '张三',
                style: TextStyle(fontSize: 15, color: SQColor.color_222222),
              ),
            ),
            Container(
              width: 80,
              child: Text(
                '水泥班组',
                style: TextStyle(fontSize: 15, color: SQColor.color_222222),
              ),
            ),
            Container(
              width: 80,
              child: Text(
                '管理人员',
                style: TextStyle(fontSize: 15, color: SQColor.color_222222),
              ),
            ),
            Expanded(
              child: Container(
                padding: EdgeInsets.only(right: 10),
                alignment: Alignment.centerRight,
                child: Text(
                  '2021-11-22  09:30:12'.replaceAll('  ', '\r\n'),
                  style: TextStyle(fontSize: 15, color: SQColor.color_222222),
                ),
              ),
            )
          ],
        ),
        SizedBox(height: 10,),
        Divider(height: 1,color: SQColor.color_DEDEDE,)
      ],
    );
  }
}
